<!--
 * @Description: 债券持有期收益率计算器
 * @Version: 1.0
 * @Autor: chenwg
 * @Date: 2024-01-16 14:26:40
 * @LastEditors: chenwg
 * @LastEditTime: 2024-01-16 14:26:40
-->
<template>
  <div class="holdingPeriodReturnCalc">
    <module-header
      ref="stockHeader"
      @getCode="getCodeBox"
    >
    <div ref="calculateBox">
      <table-stock
        :stockLoading="allLoading"
        ref="stockBox"
        @getChecked="getChecked"
        @refreshData="refreshData"
      ></table-stock>
      <hold-fields></hold-fields>

    </div>
    </module-header>
    <div class="middle">
      <module-header
        rightType="medium"
        title="损益分析"
        @saveResult="saveResult"
      >
      <break-even-analysis></break-even-analysis>
      
       
      </module-header>
      <module-header rightType="none" title="损益分析">
        
      </module-header>
    </div>
    <module-header
      rightType="easy"
      title="试算结果对比"
      @clearStock="clearStock1"
      @downLoad="downLoad"
    >
    <jy-table :data="resultTableData">
        <jy-column
          v-for="i in resultHeader"
          :key="i.field"
          :field="i.field"
          :title="i.title"
          :align="i.align"
          :minWidth="i.minWidth"
        ></jy-column>
      </jy-table>
      
    </module-header>
  </div>
</template>

<script>
import ModuleHeader from "./components/moduleHeader.vue";
import holdFields from "./components/holdFields.vue";
import tableStock from "./components/tableStock";
import calculateBox from "./components/calculateBox";
import breakEvenAnalysis from "./components/breakEvenAnalysis";
import { resultHeader, resultData, PledgeRepoZN } from "./tableSetting.js";
import { getUserinfo } from "@/utils/native";

export default {
  components: {
    ModuleHeader,
    tableStock,
    calculateBox,
    holdFields,
    breakEvenAnalysis
  },
  props: {},
  data() {
    return {
      resultTableData: [...resultData],
      resultHeader,
      Phead: PledgeRepoZN,
      PheadData: [
        {
          aa: "正回购方（元）",
          fTradingAmount: "0",
          mTradingAmount: "0",
          reInterest: "0",
          reFee: "0",
          totalProfitLoss: "0",
        },
        {
          aa: "逆回购方（元）",
          fTradingAmount: "0",
          mTradingAmount: "0",
          reInterest: "0",
          reFee: "0",
          totalProfitLoss: "0",
        },
      ],
      analyseKey: 0,
      globalParams: {
        taxesFlag: 0,
        reCode: "R007",
      },
      stockRow: {
        rows: [
          {
            code: "",
            faceAmount: "1000.00",
            convRatio: "100.00",
          },
        ],
      },
      calculateData: {
        tradeDay: "",
        settleSpeed: 0,
        reDay: "",
        mSettleDate: "",
        reRate: "",
        accrualBasis: "A/365",
      },
      allLoading: false,
      action: "",
      ucode: "",
    };
  },
  computed: {
    allParams() {
      let all = {
        global: this.globalParams,
        basic: this.stockRow,
        cal: this.calculateData,
        action: this.action,
        ucode: this.ucode,
      };
      return all;
    },
  },
  methods: {
    cellClassName({ rowIndex, row, columnIndex }) {
      if ([0].includes(rowIndex)) {
        return "reverse-head reverse-common";
      } else {
        if (
          columnIndex > 0 &&
          this.PheadData[columnIndex - 1] &&
          this.PheadData[columnIndex - 1][row.head.field] !== 0
        ) {
          if (this.PheadData[columnIndex - 1][row.head.field].includes("-")) {
            return "greenClass";
          }
        }
      }
    },
    
    getData(val) {
      let row = resultData[0];
      this.resultTableData.push(row);
    },
    getCodeBox(val) {
      this.getCode(val);
    },
    async getCode(val) {
      const userInfo = await getUserinfo();
      this.ucode = (userInfo && userInfo.userId) || 11801020;
    },
    clearStock() {
    },
    clearStock1() {
      this.resultTableData = [];
    },
    deleteStock() {
    },
    getChecked(val, type) {
      
    },

    refreshData(obj, type){},
    saveResult(){
      this.getData([]);
    },
    downLoad(){},
    setAllData(calExt, cal, basic, global){},
    refreshCalculate(obj, type) {

      this.calculateData = JSON.parse(JSON.stringify(obj));
      this.action = type;
      this.getDay();
     
    },
  },
  mounted() {
    this.getCode();
  },
};
</script>

<style lang="less" scoped>
.holdingPeriodReturnCalc {
  .middle {
    display: flex;
    .jy-card {
      flex: 1;
    }
    .jy-card:first-child {
      margin-right: 12px;
    }
    /deep/ .calenderTable .reverse-common > .jy-cell {
      background: #eff5ff;
    }
    /deep/.calenderTable .reverse-head {
      border-bottom: 1px solid #d3e2ff;
      background: #eff5ff;
      border-right: 1px solid #d3e2ff;
      font-weight: 600;
    }
    /deep/ .calenderTable .greenClass {
      color: #52c41a;
    }
  }
}
</style>
